﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace EventReader.controls
{
    public enum DrawModeEx
    {
        TopDown,
        BottomUp
    }

    public class VLabel : Label
    {
        public VLabel()
        {
            AutoSize = false;
        }
        private DrawModeEx textDrawMode = DrawModeEx.BottomUp;
        public DrawModeEx TextDrawMode
        {
            get { return textDrawMode; }
            set { textDrawMode = value; }
        }

        private new bool AutoSize
        {
            get
            {
                return base.AutoSize;
            }
            set
            {
                base.AutoSize = false;
            }
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            float vlblControlWidth;
            float vlblControlHeight;
            float vlblTransformX;
            float vlblTransformY;
            Color controlBackColor = BackColor;
            Pen labelBorderPen = new Pen(controlBackColor, 0);
            SolidBrush labelBackColorBrush = new SolidBrush(controlBackColor);
            SolidBrush labelForeColorBrush = new SolidBrush(base.ForeColor);
            base.OnPaint(e);
            vlblControlWidth = this.Size.Width;
            vlblControlHeight = this.Size.Height;
            e.Graphics.DrawRectangle(labelBorderPen, 0, 0, vlblControlWidth, vlblControlHeight);
            e.Graphics.FillRectangle(labelBackColorBrush, 0, 0, vlblControlWidth, vlblControlHeight);


            if (this.TextDrawMode == DrawModeEx.BottomUp)
            {
                vlblTransformX = 0;
                vlblTransformY = vlblControlHeight;
                e.Graphics.TranslateTransform(vlblTransformX, vlblTransformY);
                e.Graphics.RotateTransform(270);
                e.Graphics.DrawString(this.Text, Font, labelForeColorBrush, 0, 0);
            }
            else
            {
                vlblTransformX = vlblControlWidth;
                vlblTransformY = vlblControlHeight;
                e.Graphics.TranslateTransform(vlblControlWidth, 0);
                e.Graphics.RotateTransform(90);
                e.Graphics.DrawString(this.Text, Font, labelForeColorBrush, 0, 0, StringFormat.GenericTypographic);
            }
        }

    }
}
